package com.example.skillcinema.ui.screens.main.viewmodels

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.skillcinema.db.models.Staff
import com.example.skillcinema.db.repositories.FilmForPreviewRepository
import com.example.skillcinema.db.repositories.FilmRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import jakarta.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

@HiltViewModel
class StaffListViewModel @Inject constructor(val repository: FilmForPreviewRepository) :
    ViewModel() {
    private val _staffStateFlow: MutableStateFlow<List<Staff>> = MutableStateFlow(listOf())
    val staffFlow = _staffStateFlow.asStateFlow()
    fun loadIt(id: Int, isActor: Boolean) {
        viewModelScope.launch {
            _staffStateFlow.value =
                if (isActor) repository.getActors(id) else repository.getStaff(id)
        }
    }
}